<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

class newprinter_mdl_delivery extends ome_mdl_delivery {

    var $defaultOrder = array('idx_split', 'ASC');

    /**
     * 使用 ome 的app做为调用app
     * @param app $app
     */
    function __construct($app) {

        $app = app::get('ome');
        parent::__construct($app);
    }

    /**
     * 建议修改 base_db_model 中的函数
     *
     * @param boolean $real
     * @return string
     */
    public function table_name($real=false) {
        $table_name = substr(get_class($this), strlen('newprinter') + 5);
        if ($real) {
            return kernel::database()->prefix . $this->app->app_id . '_' . $table_name;
        } else {
            return $table_name;
        }
    }

    /**
     * 重载 filter 过程,增加自定义流程
     *
     * @param Array $filter
     */
    function filter($filter) {
        return $this->_filter($filter);
    }

    function _filter($filter) {
        //增加
        if (isset($filter['defined_sql'])) {

            $addon = $filter['defined_sql'] . ' and ';
            unset($filter['defined_sql']);
        }

        return $addon . parent::filter($filter);
    }

    function getLogi_name() {

        return $this->db->select("SELECT logi_name, logi_id FROM " . $this->table_name(true) . " GROUP BY logi_id");
    }

//    function modifier_idx_split($row) {
//
//        $skuNum = $row[$this->col_prefix . 'skuNum'];
//        $itemNum = $row[$this->col_prefix . 'itemNum'];
//        $content = $row[$this->col_prefix . 'bnsContent'];
//
//        $cnts = unserialize($content);
//        $cnt = sprintf("共有 %d 种商品，总共数量为 %d 件， 具体 SKU 为： %s", $skuNum, $itemNum, @implode(', ', $cnts));
//
//        @reset($cnts);
//        $content = $cnts[@key($cnts)];
//        if ($skuNum > 1) {
//
//            $content .= ' 等';
//        }
//
//        return sprintf("<span alt='%s' title='%s'><font color='red'>(<b>%d</b> / <b>%d</b>)</font> %s</span>", $cnt, $cnt, $skuNum, $itemNum, $content);
//    }

}